cmake_minimum_required(VERSION 3.16)

project(plugin_datablock LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/../output/")
file(MAKE_DIRECTORY ${OUTPUT_DIR})  # 确保目录存在
message(STATUS "Final output path: ${OUTPUT_DIR}")
# 关键修改1: 明确查找 Core + Widgets 模块
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets)      # 修改点1
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets) # 修改点2


add_library(plugin_datablock SHARED
  plugin_datablock.cpp
  plugin_datablock.h
  plugin_datablock.ui
  plugin_datablock.json
  ../../IPlugin.h
  datablock_info.h datablock_info.cpp datablock_info.ui
  datablock_manager.h datablock_manager.cpp datablock_manager.ui
  ../../../maxtool/LineEdit/customlineedit.h
  ../../../maxtool/LineEdit/customlineedit.cpp

)

# 设置动态库输出路径（兼容Windows/Linux）
set_target_properties(plugin_datablock PROPERTIES
  LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # Linux的.so文件路径
  RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # Windows的.dll文件路径
  ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}"   # 静态库（可选）
)

# 关键修改2: 添加头文件搜索路径
target_include_directories(plugin_datablock PRIVATE
  ${CMAKE_CURRENT_SOURCE_DIR}/../..  # 确保能找到 ../../IPlugin.h
  ${CMAKE_CURRENT_SOURCE_DIR}/../../../maxtool
)

# 关键修改3: 链接 Qt Widgets 模块
target_link_libraries(plugin_datablock PRIVATE
  Qt${QT_VERSION_MAJOR}::Core
  Qt${QT_VERSION_MAJOR}::Widgets      # 新增此行
)

target_compile_definitions(plugin_datablock PRIVATE SAMPLEPLUGIN_LIBRARY)

include(ProcessorCount)        # 加载CMake的CPU核心检测模块
ProcessorCount(N)              # 获取系统CPU核心数存入变量N
if(NOT N EQUAL 0)
  set(CMAKE_JOB_POOLS
      compile_job_pool=${N}      # 编译阶段使用全部CPU核心
      link_job_pool=${N}/2       # 链接阶段使用半数核心(避免内存争用)
  )
endif()
